package com.yanqu.road.logic.helper;

import com.yanqu.road.entity.enums.eSeasonRewardType;
import com.yanqu.road.entity.season.SeasonRewardConfig;
import com.yanqu.road.utils.string.StringUtils;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class SeasonHelper {

    public static int getChannelSeasonMaxRank(int systemId, int seasonId, int conditionType, String rangeKey) {
        return 5000;
    }

    public static String getWasheRangeKey(String param6) {
        List<Integer> list = StringUtils.stringToIntegerList(param6, ";");
        List<Integer> sort = list.stream().sorted(Comparator.comparing(Integer::intValue)).collect(Collectors.toList());
        return StringUtils.listToString(sort, ';');
    }

    public static boolean matchWasheRangeKey(String key, int channelId) {
        List<Integer> list = StringUtils.stringToIntegerList(key, ";");
        return list.stream().anyMatch(item -> item == channelId);
    }

    public static SeasonRewardConfig getRankRewardConfigByMyRank(Map<Integer, SeasonRewardConfig> rankRewardConfigMap, int myRank) {
        SeasonRewardConfig resultRewardConfig = null;
        // 记录下参与奖,有排名但是找不到排名都是参与奖(目前只有积分赛)
        SeasonRewardConfig lastRewardConfig = null;
        for (SeasonRewardConfig tmpConfig : rankRewardConfigMap.values()) {
            List<Long> paramList = tmpConfig.getParamList();
            if (tmpConfig.getType() == eSeasonRewardType.JinBiaoScoreRank.getIntValue()) {
                if (paramList.get(0) == -1 && paramList.get(1) == -1) {
                    lastRewardConfig = tmpConfig;
                }
            }
            if (paramList.get(0) <= myRank && myRank <= paramList.get(1)) {
                resultRewardConfig = tmpConfig;
                break;
            }
        }
        // 有参与奖励
        if (resultRewardConfig == null && lastRewardConfig != null) {
            return lastRewardConfig;
        }
        return resultRewardConfig;
    }
}
